﻿
@{
    ViewData["Title"] = "留言";
}

<div class="doc-container" id="doc-container">
    <div class="container-fixed">
        <div class="container-inner">
            <section class="msg-remark">
                <h1>留言板</h1>
                <p>
                    沟通交流，拉近你我！
                </p>
            </section>
            <div class="textarea-wrap message" id="textarea-wrap">
                <form class="layui-form blog-editor" asp-action="Add" asp-controller="Message" asp-route-id="0">
                    <div class="layui-form-item">
                        <textarea name="content" lay-verify="content" id="remarkEditor" placeholder="请输入内容" class="layui-textarea layui-hide"></textarea>
                    </div>
                    <div class="layui-form-item">
                        <button class="layui-btn" lay-submit="formLeaveMessage" lay-filter="formLeaveMessage">提交留言</button>
                    </div>
                </form>
            </div>
        </div>
        <div class="f-cb"></div>
        <div class="mt20">
            <ul class="message-list" id="message-list">
                @*<li class="zoomIn article">
                        <div class="comment-parent">
                            <a name="remark-1"></a>
                            <img src="https://thirdqq.qlogo.cn/qqapp/101465933/7627F745B95BFAC18C6C481FE72B4EB1/100" />
                            <div class="info">
                                <span class="username">路人甲</span>
                            </div>
                            <div class="comment-content">
                                剑气纵横三万里
                            </div>
                            <p class="info info-footer">
                                <i class="fa fa-calendar" aria-hidden="true"></i>
                                <span>四川</span>
                                <span class="comment-time">2018-01-01</span>
                                <a href="javascript:;" class="btn-reply" data-targetid="1" data-targetname="路人甲">回复</a>
                            </p>
                        </div>
                        <hr />
                        <div class="replycontainer layui-hide">
                            <form class="layui-form" action="">
                                <input type="hidden" name="remarkId" value="1">
                                <input type="hidden" name="targetUserId" value="0">
                                <div class="layui-form-item">
                                    <textarea name="replyContent" lay-verify="replyContent" placeholder="请输入回复内容" class="layui-textarea" style="min-height:80px;"></textarea>
                                </div>
                                <div class="layui-form-item">
                                    <button class="layui-btn layui-btn-xs" lay-submit="formReply" lay-filter="formReply">提交</button>
                                </div>
                            </form>
                        </div>
                    </li>*@
            </ul>
        </div>
    </div>
</div>

@section styles{
    <link rel="stylesheet" href="~/css/message.css" />
}
@section loadscripts{
    <script src="~/js/pagemessage.js"></script>
    <script>
        layui.use(['jquery','flow'], function () {
            var $ = layui.jquery; //不用额外加载jQuery，flow模块本身是有依赖jQuery的，直接用即可。
            var flow = layui.flow;
            flow.load({
                elem: '#message-list' //指定列表容器
                , done: function (page, next) { //到达临界点（默认滚动触发），触发下一页
                    var lis = [];
                    //以jQuery的Ajax请求为例，请求下一页数据（注意：page是从2开始返回）
                    $.get('@Url.Content("~/Message/List?page=")' + page, function (res) {
                        //假设你的列表返回在data集合中
                        layui.each(res.data, function (index, item) {
                            var html = "";
                            var parentUserName = item.userName;
                            html += '<li class="zoomIn article"><div class="comment-parent"><a name="remark-1"></a><img src="' + item.userAvatar + '" /><div class="info"><span class="username">' + item.userName + '</span></div><div class="comment-content">' + item.content + '</div><p class="info info-footer"><i class="fa fa-calendar" aria-hidden="true"></i><span class="comment-time"> ' + item.commentDate + '</span><a href="javascript:;" class="btn-reply" data-targetid="1" data-targetname="' + item.userName +'">回复</a></p></div><hr />';
                            if (item.messages != null) {
                                layui.each(item.messages, function (index, item) {
                                    html += '<div class="comment-child"><a name="reply-1"></a><img src="' + item.userAvatar + '"><div class="info"><span class="username">' + item.userName + '</span> <span style="padding-right:0;margin-left:-5px;">回复</span> <span class="username">' + parentUserName +'</span>： <span>'+item.content+'</span></div><p class="info"><i class="fa fa-calendar" aria-hidden="true"></i><span class="comment-time"> ' + item.commentDate + '</span></p></div>';
                                });
                            }
                            html += '<div class="replycontainer layui-hide"><form class="layui-form" action="@Url.Content("~/Message/Add/")' + item.id + '"><div class="layui-form-item"><textarea name="content" lay-verify="replyContent" placeholder="请输入回复内容" class="layui-textarea" style="min-height:80px;"></textarea></div><div class="layui-form-item"><button class="layui-btn layui-btn-xs" lay-submit="formReply" lay-filter="formReply">提交</button></div></form></div></li>';

                            lis.push(html);
                        });

                        //执行下一页渲染，第二参数为：满足“加载更多”的条件，即后面仍有分页
                        //count为Ajax返回的总页数，只有当前页小于总页数的情况下，才会继续出现加载更多
                        next(lis.join(''), page < res.count);
                    });
                }
            });
        });
    </script>
}